package org.kazuhiko.pokemon3d.entity.character;

import static org.lwjgl.opengl.GL11.GL_CULL_FACE;
import static org.lwjgl.opengl.GL11.GL_LINE;
import static org.lwjgl.opengl.GL11.glCallList;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glTranslatef;

import org.kazuhiko.pokemon3d.entity.Collidable;
import org.kazuhiko.pokemon3d.entity.Flag;
import org.kazuhiko.pokemon3d.entity.TexturedModelEntity;
import org.kazuhiko.pokemon3d.physics.Collision;
import org.kazuhiko.pokemon3d.physics.Collision.Side;

public class Red extends TexturedModelEntity implements Collidable
{
	private static final String MODEL_LOCATION = "res/models/red.obj";
	
	public Red( int id, String name )
	{
		super( id, name + "(red)", MODEL_LOCATION );
		
		addFlag( Flag.DO_NOT_RENDER );
		
		getCollisions().add( new Collision( -( getWidth() / 2 ), 0, ( getDepth() / 2 ), getWidth(), getHeight(), 1, Side.FRONT ) );
		
		getCollisions().add( new Collision( -( getWidth() / 2 ), 0f, -( getDepth() / 2 ), getWidth(), getHeight(), 1, Side.BACK ) );
	}

	@Override
	public void drawCollisions()
	{
		glDisable( GL_CULL_FACE );
		for( Collision col : getCollisions() )
		{
			col.draw( GL_LINE );
		}
	}

	@Override
	public void tick()
	{
	}

	@Override
	public void update()
	{
	}
	
	@Override
	public void render()
	{
		glPushMatrix();
		glTranslatef( x(), y(), z() );
		glRotatef( -yaw() + -getDefaultYaw(), 0, 1, 0 );
		glCallList( getList() );
		glCallList( getList() );
		drawCollisions();
		glPopMatrix();
	}
}
